 // 用户注册
    @PostMapping("/register")
    //处理请求
    public ResponseEntity<String> register(@RequestBody Map<String, String> request)
    //将数据转化为map
     {
        String username = request.get("username");
    //从map中获取用户名
        String password = request.get("password");
        //从map中获取密码
        String email = request.get("email");
        //从map中获取邮箱
        String checkSql = "SELECT * FROM Users WHERE Username = ?";
        //验证用户名是否重复
        String insertSql = "INSERT INTO Users (Username, Password, Email) VALUES (?, ?, ?)";
        //插入新用户数据

        try (Connection conn = getConnection();
             PreparedStatement checkStmt = conn.prepareStatement(checkSql)) 
             //获取数据库链接，编译查询语句对象
             {
            checkStmt.setString(1, username);
            ResultSet rs = checkStmt.executeQuery();
             //执行查询结果
            if (rs.next()) {
                return ResponseEntity.status(400).body("用户名已存在");
            }
             //用户已存在，报400错误
            try (PreparedStatement insertStmt = conn.prepareStatement(insertSql)) {
                insertStmt.setString(1, username);
                insertStmt.setString(2, password);
                insertStmt.setString(3, email);
                insertStmt.executeUpdate();
            }
             //创建插入语句对象，并插入用户名，密码和邮箱
            return ResponseEntity.ok("注册成功");

        } catch (SQLException e)
        //捕获并抛出异常
         {
            e.printStackTrace();
            return ResponseEntity.status(500).body("服务器错误");
        }
    }

    // 用户登录
    @PostMapping("/login")
    public ResponseEntity<String> login(@RequestBody Map<String, String> request, HttpSession session)
    //接受map和对象
     {
        String username = request.get("username");
        String password = request.get("password");
         //获取用户名和密码
        String sql = "SELECT * FROM Users WHERE Username = ?";
         //查询user表中的的指定用户的记录
        try (Connection conn = getConnection();
             PreparedStatement stmt = conn.prepareStatement(sql)) {
         //获取数据库链接并编译sql语句对象，结束时自动关闭  
            stmt.setString(1, username);
            ResultSet rs = stmt.executeQuery();

            if (rs.next()) 
             //寻找用户名，并确认有该用户
            {
                String dbPassword = rs.getString("Password");
                //获取用户密码
                if (dbPassword.equals(password))
                //判断密码是否一致
                 {
                    session.setAttribute("userId", rs.getInt("UserID"));
                    session.setAttribute("username", rs.getString("Username"));
                    session.setAttribute("role", rs.getString("Role"));
                    return ResponseEntity.ok("登录成功");
                    //将用户id，用户名，用户角色存入对话，并显示登陆成功
                } else {
                    return ResponseEntity.status(401).body("密码错误");
                    //码不一致，显示密码错误
                }
            } else {
                return ResponseEntity.status(404).body("用户不存在");
                //没找到该用户名，显示用户不存在
            }

        } catch (SQLException e) {
            e.printStackTrace();
            return ResponseEntity.status(500).body("服务器错误");
        }
    }
    // 用户注册
    @PostMapping("/register")
    //处理请求
    public ResponseEntity<String> register(@RequestBody Map<String, String> request)
    //将数据转化为map
     {
        String username = request.get("username");
    //从map中获取用户名
        String password = request.get("password");
        //从map中获取密码
        String email = request.get("email");
        //从map中获取邮箱
        String checkSql = "SELECT * FROM Users WHERE Username = ?";
        //验证用户名是否重复
        String insertSql = "INSERT INTO Users (Username, Password, Email) VALUES (?, ?, ?)";
        //插入新用户数据

        try (Connection conn = getConnection();
             PreparedStatement checkStmt = conn.prepareStatement(checkSql)) 
             //获取数据库链接，编译查询语句对象
             {
            checkStmt.setString(1, username);
            ResultSet rs = checkStmt.executeQuery();
             //执行查询结果
            if (rs.next()) {
                return ResponseEntity.status(400).body("用户名已存在");
            }
             //用户已存在，报400错误
            try (PreparedStatement insertStmt = conn.prepareStatement(insertSql)) {
                insertStmt.setString(1, username);
                insertStmt.setString(2, password);
                insertStmt.setString(3, email);
                insertStmt.executeUpdate();
            }
             //创建插入语句对象，并插入用户名，密码和邮箱
            return ResponseEntity.ok("注册成功");

        } catch (SQLException e)
        //捕获并抛出异常
         {
            e.printStackTrace();
            return ResponseEntity.status(500).body("服务器错误");
        }
    }
